package com.otp.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.cache.SimpleImageLoader;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.Volley;
import com.otp.Activity.R;
import com.otp.model.Course;
import com.otp.model.CourseInfo;
import com.otp.util.MyVolley;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

/**
 * Created by Administrator on 2016/1/31.
 */
public class CourseListAdapter extends BaseAdapter {

    private Context context;
    private List<Course> list;

    public CourseListAdapter(Context context, List<Course> list) {
        this.context = context;
        this.list = list;
    }

    public void setList(List<Course> list){
        this.list = list;
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Course getItem(int position) {
        Log.e("Course",list.get(position).getId()+"");
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Course course  = list.get(position);
       // Log.e("position", String.valueOf(position));
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        ViewGroup group = (ViewGroup) inflater.inflate(R.layout.videoitem, null);
        ImageView imageView = (ImageView) group.findViewById(R.id.videoImage);
        if (course.getCourseImage() != null){
            SimpleImageLoader imageLoader = MyVolley.getImageLoader();
            imageLoader.get(course.getCourseImage(),
                    ImageLoader.getImageListener(imageView,
                            R.drawable.ic_launcher,
                            R.drawable.ic_launcher));
        }
        TextView videoTitle = (TextView) group.findViewById(R.id.videoTitle);
        videoTitle.setText(course.getCourseName());
        TextView videoContent = (TextView) group.findViewById(R.id.videoContent);
        videoContent.setText(course.getCourseDescription());
        return group;
    }
}
